package com.yswy.backstage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yswy.backstage.service.DomainCertificateService;
import com.yswy.backstage.service.DomainService;
import com.yswy.backstage.service.SoftnessService;
import com.yswy.domain.entity.Domain;
import com.yswy.domain.entity.DomainCertificate;
import com.yswy.domain.entity.Softness;
import com.yswy.domain.vo.dto.BaseFilter;
import com.yswy.domain.vo.gld.addOrUpate.DomainAddOrUpdate;
import com.yswy.domain.vo.gld.addOrUpate.DomainCertificateAddOrUpdate;
import com.yswy.domain.vo.gld.addOrUpate.SoftnessAddOrUpdate;
import com.yswy.domain.vo.gld.addOrUpate.base.BaseReqVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController
@RequestMapping("/domain")
@Api(tags = "域名管理")
public class DomainController {
    @Autowired
    private DomainService domainService;


    @PostMapping("/listDomain")
    @ApiOperation(value = "域名列表")
    public Page<Domain> listDomain(@RequestBody  BaseFilter req, HttpServletRequest request) {
        return domainService.listDomain(req);
    }

    @GetMapping("/AllDomain")
    @ApiOperation(value = "域名列表")
    public List<Domain> AllDomain() {
        return domainService.AllDomain();
    }


    @PostMapping("/addOrUpadteDomain")
    @ApiOperation(value = "添加修改域名")
    public void addOrUpadteDomain(@RequestBody @Validated(BaseReqVO.CREATE.class) DomainAddOrUpdate req, HttpServletRequest request) {
        domainService.addOrUpadteDomain(req);
    }

    @GetMapping("/isDomainExist")
    @ApiOperation(value = "判断域名是否存在")
    public Boolean isDomainExist(@RequestParam(value = "domainName") String domainName,
                        HttpServletRequest request) {
       return domainService.isExist(domainName);
    }

    @GetMapping("/delDomain")
    @ApiOperation(value = "删除域名")
    public void delDomain(@RequestParam(value = "softnessId") Long domainId, HttpServletRequest request) {
        domainService.delDomain(domainId);
    }



}
